home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF CDFinquire.
- *
- * Version 1.0, 4-Mar-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 4-Mar-92, J Love Original version.
- *
- ******************************************************************************/
-
- #include "cdfdist.h"
- #include "cdfinq.h"
-
- /******************************************************************************
- * Online instructions.
- ******************************************************************************/
-
- static char *instructions[] = {
- #if defined(vms)
- "Usage: $ CDFINQUIRE [/DISPLAY=<mask>] [/OUTPUT=<file-path>] [/ID]",
- " <cdf-path>",
- #endif
- #if defined(unix)
- "Usage: % cdfinquire [-display <mask>] [-output <file-path>] [-id]",
- " <cdf-path>",
- #endif
- #if defined(__MSDOS__)
- "Usage: > cdfinquire [-display <mask>] [-output <file-path>] [-id]",
- " <cdf-path>",
- #endif
- "",
- "Purpose: CDFinquire generates a report on a CDF's meta-data",
- "",
- "Parameter(s): <cdf-path>",
- " The pathname of the CDF (do not enter an extension).",
- "",
- #if defined(vms)
- "Qualifier(s): /DISPLAY=<mask>",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- "Qualifier(s): -display <mask>",
- #endif
- " The type of inquiry to be done. The <mask> is made up of",
- " the following characters (at least one must be present).",
- " i = info block (copyright, version, etc.).",
- " h = header information (dimensionality, etc.).",
- " g = global scope attribute definitions.",
- " g+ = global scope attribute definitions & entries.",
- " a = variable scope attribute definitions.",
- " v = variable definitions.",
- " v+ = variable definitions & variable scope attribute",
- " entries.",
- " If not specified, the default <mask> is 'ihg+av+'.",
- "",
- #if defined(vms)
- " /OUTPUT=<file-path>",
- " Redirects the output to a file. The file created will",
- " be named <file-path> (if <file-path> does not have an",
- " extension, `.INQ' is appended automatically). If /OUTPUT",
- " is not specified, the output is displayed at the terminal.",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -output <file-path>",
- " Redirects the output to a file. The file created will",
- " be named <file-path> (if <file-path> does not have an",
- " extension, `.inq' is appended automatically). If /OUTPUT",
- " is not specified, the output is displayed at the terminal.",
- #endif
- "",
- #if defined(vms)
- " /ID",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -id",
- #endif
- " Displays the version of the CDF library only. All other",
- " parameters/qualifiers are ignored.",
- "",
- #if defined(vms)
- "Example(s): $ CDFINQUIRE GISS_VEG",
- " $ CDFINQUIRE/DISPLAY=ig+v CDF$SMPL:GISS_VEG",
- " $ CDFINQUIRE/OUTPUT=GISS_VEGX GISS_VEG",
- " $ CDFINQUIRE/DISPLAY=ih/OUTPUT=GISS_VEGX GISS_VEG",
- " $ CDFINQUIRE/ID",
- #endif
- #if defined(unix)
- "Example(s): % cdfinquire giss_veg",
- " % cdfinquire -display ig+v ~/giss_veg",
- " % cdfinquire -output giss_vegx giss_veg",
- " % cdfinquire -display ih -output ../giss_vegx ~user/giss_veg",
- " % cdfinquire -id",
- #endif
- #if defined(__MSDOS__)
- "Example(s): > cdfinquire giss_veg",
- " > cdfinquire -display ig+v ..\\giss_veg",
- " > cdfinquire -output gissvegx giss_veg",
- " > cdfinquire -display ih -output gissvegx a:\\giss_veg",
- " > cdfinquire -id",
- #endif
- NULL };
-
- /******************************************************************************
- * Global variables.
- ******************************************************************************/
-
- CDFid id; /* CDF identifier. */
- Boolean infoON; /* Display INFO block? */
- Boolean headerON; /* Display HEADER block? */
- Boolean VAdefON; /* Display variable scope attribute definitions? */
- Boolean GAdefON; /* Display global scope attribute definitions? */
- Boolean GAentryON; /* Display global scope attribute entries? */
- Boolean VdefON; /* Display variable definitions? */
- Boolean VAentryON; /* Display variable scope attribute entries? */
- FILE *OUTfp; /* Output file pointer. */
-
- char CDFpath[MAX_PATH_LEN+1]; /* Pathname of CDF to inquire. */
-
- static Boolean mLog = TRUE; /* Message logging enabled? */
-
- /******************************************************************************
- * Main.
- ******************************************************************************/
-
- #if defined(vms)
- main (argc, argv)
- #else
- void main (argc, argv)
- #endif
- int argc;
- char *argv[];
- {
- CDFstatus status;
- char oSpec[MAX_PATH_LEN+1];
- char oDir[MAX_DIR_LEN+1];
- char oName[MAX_NAME_LEN+1];
- char CDFpathX[MAX_PATH_LEN+1];
- char *mask;
-
- QOP *qop;
- static char *validQuals[] = { "display", "output", "id", NULL };
- static int optRequired[] = { TRUE, TRUE, FALSE, 0 };
-
- /******************************************************************************
- * Process command line qualifiers/options/parameters.
- ******************************************************************************/
-
- switch (argc) {
- case 1:
- PageInst (instructions);
- Exit;
- default:
- qop = Qop (argc, argv, validQuals, optRequired);
- if (qop == NULL) ExitBAD;
-
- /*************************************************************************
- * Check for /ID,-id qualifier first (exit if specified).
- *************************************************************************/
-
- if (qop->qualEntered[2]) {
- DisplayVerRelInc ();
- Exit;
- }
-
- /*************************************************************************
- * Get CDF path.
- *************************************************************************/
-
- if (qop->Nparms < 1) {
- printf ("Missing parameter.\n");
- ExitBAD;
- }
- else {
- strcpy (CDFpath, qop->parms[0]);
- }
-
- /*************************************************************************
- * Check for /DISPLAY,-display qualifier.
- *************************************************************************/
-
- if (qop->qualEntered[0]) {
- mask = qop->qualOpt[0];
-
- if (strchr(mask,'i') != NULL || strchr(mask,'I') != NULL)
- infoON = TRUE;
- else
- infoON = FALSE;
-
- if (strchr(mask,'h') != NULL || strchr(mask,'H') != NULL)
- headerON = TRUE;
- else
- headerON = FALSE;
-
- if (strchr(mask,'a') != NULL || strchr(mask,'A') != NULL)
- VAdefON = TRUE;
- else
- VAdefON = FALSE;
-
- if (strstr(mask,"g+") != NULL || strstr(mask,"G+") != NULL) {
- GAdefON = TRUE;
- GAentryON = TRUE;
- }
- else {
- if (strchr(mask,'g') != NULL || strchr(mask,'G') != NULL) {
- GAdefON = TRUE;
- GAentryON = FALSE;
- }
- }
-
- if (strstr(mask,"v+") != NULL || strstr(mask,"V+") != NULL) {
- VdefON = TRUE;
- VAentryON = TRUE;
- }
- else {
- if (strchr(mask,'v') != NULL || strchr(mask,'V') != NULL) {
- VdefON = TRUE;
- VAentryON = FALSE;
- }
- }
- }
- else { /* Default is ihg+v+ */
- infoON = TRUE;
- headerON = TRUE;
- VAdefON = TRUE;
- GAdefON = TRUE;
- GAentryON = TRUE;
- VdefON = TRUE;
- VAentryON = TRUE;
- }
-
- /*************************************************************************
- * Check for /OUTPUT,-output qualifier.
- *************************************************************************/
-
- if (qop->qualEntered[1]) {
- strcpy (oSpec, qop->qualOpt[1]);
- ParsePath (oSpec, oDir, oName);
- if (strchr(oName,'.') == NULL) strcat (oSpec, ".inq");
- OUTfp = fopen (oSpec, "w");
- if (OUTfp == NULL) {
- printf ("Unable to open output file (%s).\n", oSpec);
- ExitBAD;
- }
- }
- else
- OUTfp = stdout;
-
- /*************************************************************************/
-
- break;
- }
-
- /******************************************************************************
- * Open CDF.
- ******************************************************************************/
-
- ExpandPath (CDFpath, CDFpathX);
- status = CDFlib (OPEN_, CDF_, CDFpathX, &id,
- NULL_);
- StatusHandler (status);
-
- /******************************************************************************
- * Output information block.
- ******************************************************************************/
-
- if (infoON) OutInfoBlock ();
-
- /******************************************************************************
- * Output header block.
- ******************************************************************************/
-
- if (headerON) OutHeaderBlock ();
-
- /******************************************************************************
- * Output global scope attributes.
- ******************************************************************************/
-
- if (GAdefON) OutGlobalAttrs ();
-
- /******************************************************************************
- * Output variable scope attributes.
- ******************************************************************************/
-
- if (VAdefON) OutVarAttrs ();
-
- /******************************************************************************
- * Output variables/variable scope attributes.
- ******************************************************************************/
-
- if (VdefON) OutVariables ();
-
- /******************************************************************************
- * Close CDF, output file (if specified), and exit.
- ******************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, id,
- CLOSE_, CDF_,
- NULL_);
- StatusHandler (status);
-
- if (OUTfp != stdout) fclose (OUTfp);
-
- Exit;
- }
-
-
-
-
-
- /******************************************************************************
- * Output information block.
- ******************************************************************************/
-
- void OutInfoBlock () {
- CDFstatus status;
- char copyright[CDF_COPYRIGHT_LEN+1];
- long version, release, increment;
-
- fprintf (OUTfp, "\nINFORMATION BLOCK\n");
- fprintf (OUTfp, "-----------------\n");
-
- status = CDFlib (SELECT_, CDF_, id,
- GET_, CDF_COPYRIGHT_, copyright,
- CDF_VERSION_, &version,
- CDF_RELEASE_, &release,
- CDF_INCREMENT_, &increment,
- NULL_);
- StatusHandler (status);
-
- fprintf (OUTfp, "%s\n", copyright);
-
- fprintf (OUTfp, "Created by CDF library version: %ld.%ld.%ld\n\n",
- version, release, increment);
-
- return;
- }
-
-
-
-
-
- /******************************************************************************
- * Output header block.
- ******************************************************************************/
-
- void OutHeaderBlock () {
- CDFstatus status;
- char CDFdir[MAX_DIR_LEN+1];
- char CDFname[MAX_DIR_LEN+1];
- long encoding, format, majority;
- long numVars, numAttrs;
- long VAcount = 0, GAcount = 0;
- long numDims, dimSizes[CDF_MAX_DIMS];
- long maxRec;
- long scope, attrN;
- int dimN;
-
- fprintf (OUTfp, "\nHEADER BLOCK\n");
- fprintf (OUTfp, "------------\n\n");
-
- status = CDFlib (SELECT_, CDF_, id,
- GET_, CDF_FORMAT_, &format,
- CDF_MAJORITY_, &majority,
- CDF_ENCODING_, &encoding,
- CDF_NUMDIMS_, &numDims,
- CDF_DIMSIZES_, dimSizes,
- CDF_NUMVARS_, &numVars,
- CDF_NUMATTRS_, &numAttrs,
- CDF_MAXREC_, &maxRec,
- NULL_);
- StatusHandler (status);
-
- for (attrN = 0; attrN < numAttrs; attrN++) {
- status = CDFlib (SELECT_, CDF_, id,
- ATTR_, attrN,
- GET_, ATTR_SCOPE_, &scope,
- NULL_);
- StatusHandler (status);
-
- switch (scope) {
- case GLOBAL_SCOPE:
- case GLOBAL_SCOPE_ASSUMED:
- GAcount++;
- break;
- case VARIABLE_SCOPE:
- case VARIABLE_SCOPE_ASSUMED:
- VAcount++;
- break;
- }
- }
-
- ParsePath (CDFpath, CDFdir, CDFname);
- fprintf (OUTfp, " CDF name..... %s\n", CDFname);
-
- fprintf (OUTfp, " Encoding..... %s\n", EncodingToken(encoding));
- fprintf (OUTfp, " Majority..... %s\n", MajorityToken(majority));
- fprintf (OUTfp, " Format....... %s\n", FormatToken(format));
-
- fprintf (OUTfp, " Records...... %ld\n", maxRec + 1);
-
- fprintf (OUTfp, " Attributes... %ld", numAttrs);
- if (GAcount > 0)
- if (VAcount > 0)
- fprintf (OUTfp, " (%ld global scope, %ld variable scope)",
- GAcount, VAcount);
- else
- fprintf (OUTfp, " (all global scope)");
- else
- if (VAcount > 0) fprintf (OUTfp, " (all variable scope)");
- fprintf (OUTfp, "\n");
-
- fprintf (OUTfp, " Variables.... %ld\n", numVars);
-
- fprintf (OUTfp, " Dimensions... %ld", numDims);
- if (numDims > 0) {
- fprintf (OUTfp, ", sizes:");
- for (dimN = 0; dimN < numDims; dimN++)
- fprintf (OUTfp, " %ld", dimSizes[dimN]);
- }
- fprintf (OUTfp, "\n\n");
-
- return;
- }
-
-
-
-
-
- /******************************************************************************
- * Output global scope attributes.
- ******************************************************************************/
-
- void OutGlobalAttrs () {
- CDFstatus status;
- long numAttrs;
- long entryN, attrN;
- long attrScope;
- long maxEntry, numEntries;
- long dataType, numElems;
- char attrName[CDF_ATTR_NAME_LEN+1];
- char delim;
- void *buffer;
- int ccc; /* Current Cursor Column. */
-
- fprintf (OUTfp, "\nGLOBAL SCOPE ATTRIBUTES\n");
- fprintf (OUTfp, "-----------------------\n\n");
-
- status = CDFlib (SELECT_, CDF_, id,
- GET_, CDF_NUMATTRS_, &numAttrs,
- NULL_);
- StatusHandler (status);
-
- for (attrN = 0; attrN < numAttrs; attrN++) {
- status = CDFlib (SELECT_, CDF_, id,
- ATTR_, attrN,
- GET_, ATTR_NAME_, attrName,
- ATTR_SCOPE_, &attrScope,
- ATTR_MAXENTRY_, &maxEntry,
- ATTR_NUMENTRIES_, &numEntries,
- NULL_);
- StatusHandler (status);
-
- if (attrScope == GLOBAL_SCOPE || attrScope == GLOBAL_SCOPE_ASSUMED) {
- /*************************************************************************
- * Global scope attribute.
- *************************************************************************/
-
- delim = PickDelim (attrName);
- fprintf (OUTfp, "%3ld. Name...... %c%s%c\n",
- attrN + 1, delim, attrName, delim);
- fprintf (OUTfp, " Entries... %ld\n\n", numEntries);
-
- if (GAentryON && numEntries > 0) {
- for (entryN = 0; entryN <= maxEntry; entryN++) {
- status = CDFlib (SELECT_, CDF_, id,
- ENTRY_, entryN,
- GET_, ENTRY_DATATYPE_, &dataType,
- ENTRY_NUMELEMS_, &numElems,
- NULL_);
- if (status != NO_SUCH_ENTRY) {
- StatusHandler (status);
-
- fprintf (OUTfp, " Number...... %ld\n", entryN + 1);
- fprintf (OUTfp, " Data type... CDF%s (%ld elements)\n",
- DataTypeToken(dataType), numElems);
-
- MALLOC (buffer, ElemSize(dataType) * numElems);
- status = CDFlib (SELECT_, CDF_, id,
- GET_, ENTRY_DATA_, buffer,
- NULL_);
- StatusHandler (status);
-
- if (STRINGdataType(dataType))
- ccc = fprintf (OUTfp, " Value....... ");
- else
- ccc = fprintf (OUTfp, " %s...... ",
- (numElems > 1 ? "Values" : "Value."));
- WriteEntryValue (OUTfp, dataType, numElems, buffer, ccc,
- MAX_COL_TO_USE);
- fprintf (OUTfp, "\n\n");
-
- free (buffer);
- }
- }
- }
- }
- }
-
- return;
- }
-
-
-
-
-
- /******************************************************************************
- * Output variable scope attributes.
- ******************************************************************************/
-
- void OutVarAttrs () {
- CDFstatus status;
- long numAttrs;
- long attrN;
- long attrScope;
- long numEntries;
- char attrName[CDF_ATTR_NAME_LEN+1];
- char delim;
-
- fprintf (OUTfp, "\nVARIABLE SCOPE ATTRIBUTES\n");
- fprintf (OUTfp, "-------------------------\n\n");
-
- status = CDFlib (SELECT_, CDF_, id,
- GET_, CDF_NUMATTRS_, &numAttrs,
- NULL_);
- StatusHandler (status);
-
- for (attrN = 0; attrN < numAttrs; attrN++) {
- status = CDFlib (SELECT_, CDF_, id,
- ATTR_, attrN,
- GET_, ATTR_NAME_, attrName,
- ATTR_SCOPE_, &attrScope,
- ATTR_NUMENTRIES_, &numEntries,
- NULL_);
- StatusHandler (status);
-
- if (attrScope == VARIABLE_SCOPE || attrScope == VARIABLE_SCOPE_ASSUMED) {
- /*************************************************************************
- * Variable scope attribute.
- *************************************************************************/
-
- delim = PickDelim (attrName);
- fprintf (OUTfp, "%3ld. Name...... %c%s%c\n",
- attrN + 1, delim, attrName, delim);
- fprintf (OUTfp, " Entries... %ld\n\n", numEntries);
- }
- }
-
- return;
- }
-
-
-
-
-
- /******************************************************************************
- * Output variables/variable scope attributes.
- ******************************************************************************/
-
- void OutVariables () {
- CDFstatus status;
- long varN, attrN;
- long numVars, numAttrs;
- long dataType, numElems;
- char varName[CDF_VAR_NAME_LEN+1];
- char attrName[CDF_ATTR_NAME_LEN+1];
- long numDims;
- long recVary, dimVarys[CDF_MAX_DIMS];
- char delim;
- int dimN;
- long attrScope;
- void *buffer;
- int ccc; /* Current Cursor Column. */
-
- fprintf (OUTfp, "\nVARIABLES\n");
- fprintf (OUTfp, "---------\n\n");
-
- status = CDFlib (SELECT_, CDF_, id,
- GET_, CDF_NUMVARS_, &numVars,
- CDF_NUMATTRS_, &numAttrs,
- CDF_NUMDIMS_, &numDims,
- NULL_);
- StatusHandler (status);
-
- for (varN = 0; varN < numVars; varN++) {
- status = CDFlib (SELECT_, CDF_, id,
- VAR_, varN,
- GET_, VAR_NAME_, varName,
- VAR_DATATYPE_, &dataType,
- VAR_NUMELEMS_, &numElems,
- VAR_RECVARY_, &recVary,
- VAR_DIMVARYS_, dimVarys,
- NULL_);
- StatusHandler (status);
-
- delim = PickDelim (varName);
- fprintf (OUTfp, "%3ld. Name........ %c%s%c\n",
- varN + 1, delim, varName, delim);
- fprintf (OUTfp, " Data type... CDF%s (%ld element%s)\n",
- DataTypeToken(dataType), numElems, (numElems == 1 ? "" : "s"));
- fprintf (OUTfp, " Variances... %s/", TFvarianceToken(recVary));
- if (numDims > 0) {
- for (dimN = 0; dimN < numDims; dimN++)
- fprintf (OUTfp, "%s", TFvarianceToken(dimVarys[dimN]));
- }
- fprintf (OUTfp, "\n\n");
-
- if (VAentryON) {
- for (attrN = 0; attrN < numAttrs; attrN++) {
- status = CDFlib (SELECT_, CDF_, id,
- ATTR_, attrN,
- GET_, ATTR_NAME_, attrName,
- ATTR_SCOPE_, &attrScope,
- NULL_);
- StatusHandler (status);
-
- if (attrScope == VARIABLE_SCOPE ||
- attrScope == VARIABLE_SCOPE_ASSUMED) {
- /********************************************************************
- * Variable scope attribute.
- ********************************************************************/
-
- status = CDFlib (SELECT_, CDF_, id,
- ENTRY_, varN,
- GET_, ENTRY_DATATYPE_, &dataType,
- ENTRY_NUMELEMS_, &numElems,
- NULL_);
- if (status != NO_SUCH_ENTRY) {
- StatusHandler (status);
-
- fprintf (OUTfp, " Attribute name... %c%s%c\n",
- delim, attrName, delim);
- fprintf (OUTfp,
- " Data type........ CDF%s (%ld element%s)\n",
- DataTypeToken(dataType), numElems,
- (numElems == 1 ? "" : "s"));
-
- MALLOC (buffer, numElems * ElemSize(dataType));
- status = CDFlib (SELECT_, CDF_, id,
- GET_, ENTRY_DATA_, buffer,
- NULL_);
- StatusHandler (status);
-
- if (STRINGdataType(dataType))
- ccc = fprintf (OUTfp, " Value............ ");
- else
- ccc = fprintf (OUTfp, " %s........... ",
- (numElems > 1 ? "Values" : "Value."));
- WriteEntryValue (OUTfp, dataType, numElems, buffer, ccc,
- MAX_COL_TO_USE);
- fprintf (OUTfp, "\n\n");
-
- free (buffer);
- }
- }
- }
- }
- }
-
- return;
- }
-
-
-
-
-
- /******************************************************************************
- * Display CDF library version/release/increment/sub-increment.
- ******************************************************************************/
-
- void DisplayVerRelInc () {
- CDFstatus status;
- long version, release, increment;
- char subincrement;
-
- status = CDFlib (GET_, LIB_VERSION_, &version,
- LIB_RELEASE_, &release,
- LIB_INCREMENT_, &increment,
- LIB_subINCREMENT_, &subincrement,
- NULL_);
- StatusHandler (status);
-
- printf ("CDF distribution V%ld.%ld.%ld%c\n",
- version, release, increment, subincrement);
-
- return;
- }
-
-
-
-
-
- /******************************************************************************
- * StatusHandler.
- ******************************************************************************/
-
- void StatusHandler (status)
- CDFstatus status;
- {
- char text[CDF_STATUSTEXT_LEN + 1];
-
- if (status == CDF_OK) return; /* Do nothing. */
-
- CDFlib (SELECT_, CDF_STATUS_, status,
- GET_, STATUS_TEXT_, text,
- NULL_);
-
- if (status < CDF_WARN) {
- printf ("ERROR> %s\n", text);
- ExitBAD;
- }
- else
- if (mLog)
- if (status < CDF_OK)
- printf ("WARNING> %s\n", text);
- else
- printf ("INFO> %s\n", text);
-
- return;
- }
-